import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-14
 * Time: 15:30
 */
public class Demo34 {
    public static void main(String[] args) {
        Object locker1 = new Object();
//        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
            System.out.println("t1线程等待前");
           synchronized (locker1) {
               try {
                   locker1.wait(10000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
            System.out.println("t1线程等待后");
        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2线程等待前");
            synchronized (locker1) {
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t2线程等待后");
        });
        t1.start();
        t2.start();
        Scanner sc = new Scanner(System.in);
        System.out.println("任意输入一个整数：");
        sc.nextInt();
        synchronized (locker1) {
//            locker1.notify();//一个notify只会随机唤醒t1和t2中其中一个wait
//            locker1.notify();
            locker1.notifyAll();//先唤醒其中一个等第一个线程解锁后才唤醒第二个
        }
    }
}
